﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainDriver.DomainModeling.DomainObjects
{
    public class KeyBasedEqualityComparer<KEY, KEYED_DOMAIN_OBJECT> : IEqualityComparer<KEYED_DOMAIN_OBJECT>
        where KEYED_DOMAIN_OBJECT : IKeyedDomainObject<KEY, KEYED_DOMAIN_OBJECT>
    {
        public virtual bool Equals(KEYED_DOMAIN_OBJECT x, KEYED_DOMAIN_OBJECT y)
        {
            if ((x == null) || (y == null))
            { throw new InvalidOperationException("The objects to compare must not be null."); }

            return x.Key.Equals(y.Key);
        }

        public virtual int GetHashCode(KEYED_DOMAIN_OBJECT obj)
        {
            return obj.Key.GetHashCode();
        }
    }
}